from sqlalchemy import Column, BigInteger, String, DECIMAL, Integer, DateTime, Index, ForeignKey
from sqlalchemy.orm import relationship

from config.database import BaseMixin, Base


class BgUserAffiliate(Base, BaseMixin):
    """用户推广信息表"""
    __tablename__ = 'bg_user_affiliate'

    user_id = Column(BigInteger, ForeignKey('sys_user.user_id'), nullable=False, comment='用户ID', index=True, )
    affiliate_code = Column(String(32), nullable=False, unique=True, comment='推广码')
    commission_rate = Column(DECIMAL(5, 2), nullable=False, default=5.00, comment='返利比例(%)')
    total_commission = Column(DECIMAL(10, 2), nullable=False, default=0.00, comment='累计返利金额')
    status = Column(Integer, nullable=False, default=1, comment='状态(0:禁用 1:启用)')
    ali_pay_account = Column(String(100), nullable=True, comment='支付宝账号')
    ali_pay_name = Column(String(50), nullable=True, comment='支付宝真实姓名')

    # 关联关系
    user = relationship("SysUser", foreign_keys=[user_id], back_populates="affiliate_info")
